package process;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import Power_Asisst.main.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomArrayAdapter extends ArrayAdapter<String> {
	private final Context context;
	private final List<String> values;
	private final List<String> dd = new ArrayList<String>();
	String b ="";
	public CustomArrayAdapter(Context context, int a, List<String> values) {
		super(context, R.layout.imagelistview, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.imagelistview, null);
		TextView textView = (TextView) rowView.findViewById(R.id.label);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
		String s = values.get(position);
		textView.setText(s);
		int length = s.lastIndexOf(".");// lấy chiều dài của file
												// từ đầu đến dấu chấm
		String DuoiFile = s.substring(length + 1);
		
		if(s.endsWith("/"))
		{
			imageView.setImageResource(R.drawable.fo2);
		}
		else if(DuoiFile.equals("apk"))
		{
			imageView.setImageResource(R.drawable.ad);
		}
		else if(DuoiFile.equals("mp3"))
		{
			imageView.setImageResource(R.drawable.nhac7);
		}
		else if(DuoiFile.equals("pdf"))
		{
			imageView.setImageResource(R.drawable.pdf);
		}
		else if(DuoiFile.equals("ppt")||DuoiFile.equals("pptx"))
		{
			imageView.setImageResource(R.drawable.ppt1);
		}
		else if(DuoiFile.equals("doc"))
		{
			imageView.setImageResource(R.drawable.wo);
		}
		else if(DuoiFile.equals("txt"))
		{
			imageView.setImageResource(R.drawable.txt1);
		}
		else if(DuoiFile.equals("jpg")||DuoiFile.equals("JPG")||DuoiFile.equals("png")||DuoiFile.equals("gif"))
		{
			String fname=new File(getFilesDir(), s).getAbsolutePath();
			Bitmap res = BitmapFactory.decodeFile(fname);
			imageView.setImageResource(R.drawable.image);
		}
		else if(DuoiFile.equals("mp4"))
		{
			imageView.setImageResource(R.drawable.video);
		}
		else 
		{
			imageView.setImageResource(R.drawable.b1);
		}
 
		return rowView;
	}

	private File getFilesDir() {
		// TODO Auto-generated method stub
		return null;
	}
}
